<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>question</title>

<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
		function select(){
			var size = document.getElementById("pageSize");
			var selectForm = document.getElementById("selectForm");
			selectForm.action = "${pageContext.request.contextPath}/question/queryAnswer.action";
			selectForm.submit();
		}
		function asubmit(){
			var answerForm = document.getElementById("answerForm");
			answerForm.action = "${pageContext.request.contextPath}/question/addAnswer.action";
			answerForm.submit();
		}
		function clickLike(obj){
			$.ajax({
				url:"${pageContext.request.contextPath}/question/addLike.action",
				data:"answerId="+obj.value,
				success:function(data){
					$("span[name='"+obj.value+"']").text(data.answer.likeNum);
					if(data.msg!=null){
						alert(data.msg);
					}
				}
			
			});
		}
	</script>
</head>

<body>


	<table>
		<thead>
			<th>序号</th>
			<th>内容</th>
			<th>操作</th>
		</thead>
		<tbody>
			<s:iterator value="#request.pageBean.list" id="q">
				<s:iterator value="#q.answers" id="a" status="st">
					<tr>
						<td><s:property value="#st.count" /></td>
						<td><s:property value="#a.content" /></td>
						<td>
							<span name="<s:property value="#a.id"/>" ><s:property value="#a.likeNum"/></span><button value="<s:property value="#a.id"/>" onclick="clickLike(this)">点赞</button>
						</td>
					</tr>
				</s:iterator>
			</s:iterator>

		</tbody>
	</table>
	<form action="javascript:;" method="post" id="answerForm">
		<input type="hidden" name="question.id" value="${question.id}" />
		<textarea rows="6" cols="20" name="answer.content"></textarea>
		<s:token></s:token>
		<button onclick="asubmit()">我要回答</button>
	</form>
	<p>当前页：${pageBean.currentPage}，总页数：${pageBean.totalPage}</p>
	<c:if test="${pageBean.currentPage!=1 }">
		<a
			href="${pageContext.request.contextPath}/question/queryAnswer?pageBean.currentPage=1&question.id=${questionId}">首页</a>
	</c:if>
	<c:if test="${pageBean.currentPage==1 }">
		<a>首页</a>
	</c:if>
	<c:if test="${pageBean.hasPrePage}">
		<a
			href="${pageContext.request.contextPath}/question/queryAnswer?pageBean.currentPage=${pageBean.currentPage-1}&question.id=${questionId}">上一页</a>
	</c:if>
	<c:if test="${pageBean.hasPrePage==false}">
		<a>上一页</a>
	</c:if>
	<c:if test="${pageBean.hasNextPage}">
		<a
			href="${pageContext.request.contextPath}/question/queryAnswer?pageBean.currentPage=${pageBean.currentPage+1}&question.id=${questionId}">下一页</a>
	</c:if>
	<c:if test="${pageBean.hasNextPage==false}">
		<a>下一页</a>
	</c:if>
	<c:if test="${pageBean.totalPage!=pageBean.currentPage}">
		<a
			href="${pageContext.request.contextPath}/question/queryAnswer?pageBean.currentPage=${pageBean.totalPage}&question.id=${questionId}">尾页</a>
	</c:if>
	<c:if test="${pageBean.totalPage==pageBean.currentPage}">
		<a>尾页</a>
	</c:if>
	<form action="#" method="post" id="selectForm">
		<input type="hidden" name="question.id" value="${question.id}" /> <select
			name="pageBean.everyPage" id="pageSize" onchange="select()">
			<option value="5"
				<c:if test="${pageBean.everyPage eq 5}">selected</c:if>>5</option>
			<option value="10"
				<c:if test="${pageBean.everyPage eq 10}">selected</c:if>>10</option>
			<option value="20"
				<c:if test="${pageBean.everyPage eq 20}">selected</c:if>>20</option>
			<option value="30"
				<c:if test="${pageBean.everyPage eq 30}">selected</c:if>>30</option>
		</select>
	</form>
</body>
</html>
